import React from "react";
import { BrowserRouter, NavLink, Route, Redirect } from "react-router-dom";
const index = () => {
  return (
    <BrowserRouter>
      <nav>
        <NavLink activeStyle={{ color: "red" }} to="/home">
          首页
        </NavLink>
        <NavLink activeStyle={{ color: "red" }} to="/news">
          新闻
        </NavLink>
      </nav>
      <main>
        <Redirect
          to={{
            pathname: "/home",
            search: "?name=xiaoming&age=23",
            state: { name: "小明", age: "23岁" }
          }}
        />
        <Route
          path="/home"
          component={props => {
            console.log(props.location);
            return <div>我是首页</div>;
          }}
        />
        <Route path="/news" component={() => <div>我是新闻</div>} />
      </main>
    </BrowserRouter>
  );
};

export default index;
